#pragma once

#include <QtCore/QCoreApplication>
#include <qprocess.h>

#include "Board.h"

class HexJudgerConsole : public QObject
{
	Q_OBJECT

private:

	char path1[1000];
	char path2[1000];

	QProcess * engine1 = nullptr;
	QProcess * engine2 = nullptr;

	int lastMove = -1;
	int switchFlag = false;

	int cmd1 = 0;
	int cmd2 = 0;

	Board board;

	void writeAndWait(QProcess * process, const char * str);

public:
	HexJudgerConsole(int argc, char ** argv);
	~HexJudgerConsole();

	void readPath();
	void setPath(const char * str1, const char * str2);
	void createEngine();
	void connectEngineToSlots();
	void startEngine();
	int startSimulation();
	void killProcess();

	void printBoard(const Board & board);
	
	int flip(int pos) {
		int x = pos / 11;
		int y = pos % 11;

		return y * 11 + x;
	}

public slots:
	void onEngine1ReadyRead();
	void onEngine2ReadyRead();
};